package com.server.questionbank.snframe.mapper.Course.Resource;

import com.server.questionbank.snframe.controller.Course.pojo.Resource.CreateCourseResource;
import com.server.questionbank.snframe.domain.Course.Resource.CourseResource;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseResourcesMapper {
    // 获取课程资源列表
    @Select("SELECT * FROM course_resource WHERE course_id = #{courseId};")
    public List<CourseResource> getResourceList(@Param("courseId") Long courseId);

    // 获取课程资源信息
    @Select("SELECT * FROM course_resource WHERE resource_id = #{resourceId};")
    public CourseResource getResourceInfo(@Param("resourceId") Long resourceId);

    // 通过文件ID获取课程资源信息
    @Select("SELECT course_resource.* FROM course_resource " +
            "JOIN course_files ON course_resource.resource_id = course_files.resource_id " +
            "WHERE course_files.file_id = #{fileId} ")
    public CourseResource getResourceInfoByFileId(@Param("fileId") Long fileId);

    // 创建课程资源
    @Insert("INSERT INTO course_resource (course_id, resource_name, uploadUserId) VALUES (#{newResource.courseId}, #{newResource.resourceName}, #{createBy})")
    @Options(useGeneratedKeys = true, keyProperty = "newResource.resourceId")
    public Integer createResource(@Param("newResource") CreateCourseResource newResource, @Param("createBy") Long createBy);
}
